package cosc617_blackteam;

import java.util.Iterator;

/**
 * @author Laura
 * command to get a comment collection of approved comments
 */
public class CmdGetApprovedComments implements I_Command {

    private I_InfoAggregator infoAggr;

    public CmdGetApprovedComments(I_InfoAggregator infoAggr) {
        this.infoAggr = infoAggr;
    }

    /*
     * @return a copy of all comments in a collection.
     */
    @Override
    public Object execute() {
        Iterator<Comment> ci = infoAggr.getComments().approvedCommentIterator();
        CommentCollection comments = new CommentCollection();
        while (ci.hasNext()) {
            comments.addComment(ci.next().copy());
        }
        return comments;
    }

}
